import {request} from "../../request/index.js"
Page({
  data:{
    nickName:'',
    age:'',
    // 阶段
    period:'',
    // 护肤重点
    emphasis:'',
    // 洗面奶
    faceWash:'',
    // 水乳
    makeUpWL:'',
    // 面霜
    cream:'',
    // 精华
    essence:'',
  },
  onLoad(){
    let that = this;
    // 获取本地存储的用户昵称、面龄
    wx.getStorage({
      key: 'nickName',
      success: function(res){
        that.setData({
          nickName:res.data
        })
      }
    });
    wx.getStorage({
      key: 'age',
      success: function(res){
        that.setData({
          age:res.data
        })
      }
    });
    // 调用getSkinCare 得到信息
    setTimeout(function(){that.getSkinCare(that.data.age)},100)
  },
  // 发请求 获取针对性护肤产品数据
  async getSkinCare(age){
    const res = await request({url:"/result",method:'Post',data:{age}})
    this.setData({
      period:res.data.result.period,
      emphasis:res.data.result.emphasis,
      faceWash:res.data.result.faceWash,
      makeUpWL:res.data.result.makeUpWL,
      cream:res.data.result.cream,
      essence:res.data.result.essence,
    })
  },
  // 跳转到商城
  toStore(){
    wx.switchTab({
      url: '../storeIndex/storeIndex'
    })
  }
})
